﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DM01State : MonoBehaviour {

	// Use this for initialization
	void Start () {
        Context context = new Context();
        context.SetState(new ConcreteStateA(context));
        context.Handle(3);
        context.Handle(11);
        context.Handle(16);
        context.Handle(40);
        context.Handle(50);
	}
	
	
}

public class Context{
	IState m_state = null;
    public void SetState(IState state)
    {
        m_state = state;
    }
    public void Handle(int arg)
    {
        m_state.Handle(arg);
    }
}

public abstract class IState{
	protected Context m_context=null;
	public IState(Context thecontext){
		m_context = thecontext;
	}
	public abstract void Handle (int arg);
}

public class ConcreteStateA:IState{

    public ConcreteStateA(Context theContext) : base(theContext) { }

	public override void Handle(int arg){
		Debug.Log ("ConcreteStateA +Handle() is running");
		if (arg > 10) {
            //Operate ConcreteStateB 
            m_context.SetState(new ConcreteStateB(m_context));
            
		}
	}
}

public class ConcreteStateB:IState{
    public ConcreteStateB(Context theContext) : base(theContext) { }
    public override void Handle(int arg) {
        Debug.Log("ConcreteStateB +Handle() is running");
        if (arg > 15)
        {
            //Operate ConcreteStateC
            m_context.SetState(new ConcreteStateC(m_context));
        }
    } 
}

public class ConcreteStateC : IState
{
    public ConcreteStateC(Context thecontext) : base(thecontext)
    {
    }
    public override void Handle(int arg) {
        Debug.Log("ConcreteStateC +Handle() is running ");
        if (arg > 20) {
            //Operate ConcreteStateA
            m_context.SetState(new ConcreteStateA(m_context));
                }
    }
}



